package com.hsylient.servlet;

import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "cookieSendServlet", value = "/send-servlet")
public class CookieSendServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Cookie cookie = new Cookie("username", URLEncoder.encode("黄涛", StandardCharsets.UTF_8));
        cookie.setMaxAge(10);
        cookie.setPath("*/accept-servlet");
        cookie.setVersion(3);
        cookie.setHttpOnly(Boolean.TRUE);
        cookie.setComment("comment");
        response.addCookie(cookie);
    }

    public void destroy() {
    }
}